package com.edu.aspect;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @Component 把当前通知类 放入容器
 * @Aspect 表示这个类是一个通知类
 * @Order 配置这个切面的执行顺序
 */
@Aspect
@Component
@Order
public class MyAspect {

    //定义切点
    @Pointcut("execution(* com.edu.service..*.*(..))")
    public void pt1(){}

    @Before("execution(* com.edu.service..*.*(..))")
    public void before(JoinPoint jt){
        System.out.println(jt.getSignature().getName()+"执行了前置通知");
    }

    @AfterReturning(pointcut = "pt1()",returning = "result")
    public void afterR(JoinPoint jt,Object result){
        System.out.println("执行了后置返回通知");
    }

    @AfterThrowing(pointcut = "pt1()",throwing = "e")
    public void afterT(JoinPoint jt,Exception e){
        System.out.println("发生了异常，类型是"+e);
    }
}
